local skel = fk.CreateSkill{--定义
  name = "kqf__paoshi",
  tags = { Skill.Switch },
}

local DIY = require "packages/diy_utility/diy_utility"

Fk:loadTranslationTable{--翻译
  ["kqf__paoshi"] = "袍虱",
  [":kqf__paoshi"] = "转换技，你可以将中央区两张基本牌置于牌堆两侧，视为使用一张与二者牌名①皆相同②皆不同的基本牌。",

  ["#kqf__paoshi_yang"] = "袍虱：你可以将中央区两张基本牌置于牌堆两侧，视为使用一张与二者牌名皆相同的基本牌",
  ["#kqf__paoshi_ying"] = "袍虱：你可以将中央区两张基本牌置于牌堆两侧，视为使用一张与二者牌名皆不同的基本牌",

  ["$kqf__paoshi1"] = "香莲宝箧，奇珍异物。",
  ["$kqf__paoshi2"] = "宝箧有寓，得其者方便识局。",
}

skel:addAcquireEffect(function (self, player, is_start)--DIYU的中央区加入游戏
  player.room:addSkill("#CenterArea")
end)

skel:addEffect("viewas", {
  pattern = ".|.|.|.|.|basic",
  prompt = function (self, player, selected_cards, selected)
    if player:getSwitchSkillState(skel.name) == fk.SwitchYang then
      return "#kqf__paoshi_yang"
    else
      return "#kqf__paoshi_ying"
    end
  end,
  interaction = function(self, player)
    local all_names = Fk:getAllCardNames("b")
    local all_names_b = player:getViewAsCardNames(skel.name, all_names)
    local cids = DIY.getCenterCards(Fk:currentRoom())
    local names = {}
    for _,name in ipairs(all_names_b) do
      if player:getSwitchSkillState(skel.name) == fk.SwitchYang then
        --相同
        if #table.filter(cids,function (element, index, array)
          local card = Fk:getCardById(element)
          return card.trueName == name and card.type == Card.TypeBasic
        end) > 1 then
          table.insert(names,name)
        end
      else
        --不同
        if #table.filter(cids,function (element, index, array)
          local card = Fk:getCardById(element)
          return card.trueName ~= name and card.type == Card.TypeBasic
        end) > 1 then
          table.insert(names,name)
        end
      end
    end
    if #names > 0 then
      return UI.CardNameBox { choices = names, all_choices = all_names }
    end
  end,
  card_filter = Util.FalseFunc,
  view_as = function(self, player, cards)
    if self.interaction.data == nil then return end
    local card = Fk:cloneCard(self.interaction.data)
    card.skillName = skel.name
    return card
  end,
  before_use = function (self, player, use)
    local name = use.card.trueName
    local cards = DIY.getCenterCards(Fk:currentRoom())
    local list = {}
    for _,cid in ipairs(DIY.getCenterCards(Fk:currentRoom())) do
      if player:getSwitchSkillState(skel.name,true) == fk.SwitchYang then
        --
        local card = Fk:getCardById(cid)
        if card.trueName == name and card.type == Card.TypeBasic then
          table.insert(list,cid)
        end
      else
        --
        local card = Fk:getCardById(cid)
        if card.trueName ~= name and card.type == Card.TypeBasic then
          table.insert(list,cid)
        end
      end
    end
    if #list > 2 then
      _,list =player.room:askToChooseCardsAndPlayers(player, {
        min_card_num = 2,
        max_card_num = 2,
        min_num = 0,
        max_num = 0,
        targets = {},
        pattern = ".|.|.|^(hand,equip)",
        expand_pile = list,
        skill_name = skel.name,
        cancelable = false,
      })
    end
    if #list > 0 then
      DIY.removeCenterCards(player,list)
      player.room:askToGuanxing(player,{
        cards = list,
        top_limit = {1,1},
        skill_name = skel.name,
      })
    end
  end
})

return skel